package com.action.blog.menu;

import java.util.Map;

import com.db.blog.menu.MenuadManager;
import com.db.blog.menu.MenuadVO;
import com.opensymphony.xwork2.ActionContext;

public class UpDownAction {
	private Integer[] orderno;
	private String updown;

	private MenuadManager menuad;

	public MenuadManager getMenuad() {
		return menuad;
	}

	public void setMenuad(MenuadManager menuad) {
		this.menuad = menuad;
	}

	public void setOrderno(Integer[] orderno) {
		this.orderno = orderno;
	}

	public void setUpdown(String updown) {
		this.updown = updown;
	}

	public String Up() throws Exception {
		MenuadVO vo = new MenuadVO();
		Map session = ActionContext.getContext().getSession();
		vo.setIdtype((String) session.get("login"));

		int max = menuad.CountSelect(vo);

		for (int i = 0; i < orderno.length; i++) {

			System.out.println("for(orderno):" + orderno[i]);
			if (orderno[i] != max) {
				vo.setOrderno(orderno[i]);
				menuad.DownUpdate(vo);
			}
		}
		System.out.println("up:" + updown);
		return "success";
	}

	public String Down() throws Exception {
		MenuadVO vo = new MenuadVO();
		Map session = ActionContext.getContext().getSession();
		vo.setIdtype((String) session.get("login"));

		for (int i = 0; i < orderno.length; i++) {
			if (orderno[i] != 1) {
				vo.setOrderno(orderno[i]);
				menuad.UpUpdate(vo);
			}
		}
		System.out.println("down" + updown);
		return "sccess";
	}
}
